package com.blueberry.commbank.persistence;

import com.blueberry.commbank.domain.entity.Account;
import com.blueberry.commbank.domain.entity.Money;
import java.math.BigDecimal;
import java.util.Currency;

public class AccountDO {
    private Integer id;
    private String accountId;
    private String accountNumber;
    private String pinNumber;
    private String currencyCode;
    private BigDecimal balance;
    private BigDecimal dailyLimit;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getAccountId() {
        return accountId;
    }

    public void setAccountId(String accountId) {
        this.accountId = accountId;
    }

    public String getAccountNumber() {
        return accountNumber;
    }

    public void setAccountNumber(String accountNumber) {
        this.accountNumber = accountNumber;
    }

    public String getPinNumber() {
        return pinNumber;
    }

    public void setPinNumber(String pinNumber) {
        this.pinNumber = pinNumber;
    }

    public String getCurrencyCode() {
        return currencyCode;
    }

    public void setCurrencyCode(String currencyCode) {
        this.currencyCode = currencyCode;
    }

    public BigDecimal getBalance() {
        return balance;
    }

    public void setBalance(BigDecimal balance) {
        this.balance = balance;
    }

    public BigDecimal getDailyLimit() {
        return dailyLimit;
    }

    public void setDailyLimit(BigDecimal dailyLimit) {
        this.dailyLimit = dailyLimit;
    }

    public static Account toAccount(AccountDO accountDO) {
        Account account = new Account();
        account.setId(accountDO.getId());
        account.setAccountId(accountDO.getAccountId());
        account.setAccountNumber(accountDO.getAccountNumber());
        account.setPinNumber(accountDO.getPinNumber());
        account.setBalance(new Money(accountDO.getBalance(),
                Currency.getInstance(accountDO.currencyCode)));
        account.setDailyLimit(new Money(accountDO.getDailyLimit(),
                Currency.getInstance(accountDO.currencyCode)));
        return account;
    }

    public static AccountDO valueOf(Account account) {
        AccountDO accountDO = new AccountDO();
        accountDO.setId(account.getId());
        accountDO.setAccountId(account.getAccountId());
        accountDO.setAccountNumber(account.getAccountNumber());
        accountDO.setPinNumber(account.getPinNumber());
        accountDO.setCurrencyCode(account.getCurrency().getCurrencyCode());
        accountDO.setBalance(account.getBalance().getAmount());
        accountDO.setDailyLimit(account.getDailyLimit().getAmount());
        return accountDO;
    }
}
